package com.jay.compass;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

public class FragmentStatus extends Fragment {

	private LinearLayout about;
	private FragmentCallbackListener mListener;
	private String mCardId = "----";
	private int mConnectType = LoginActivity.CONNECT_TYPE_NONE;
	private int mConnectStatus = 0;
	private int mBattery = 100;
	private int mIcStatus = 1;
	private int mHwStatus = 1;
	private TextView cardNumberTextView;
	private TextView connectStatusTextView;
	private TextView connectTypeTextView;
	private TextView batteryTextView;
	private TextView icStatusTextView;
	private TextView hwStatusTextView;

	@Override
	public void onAttach(Activity activity) {
		// TODO Auto-generated method stub
		super.onAttach(activity);
		mListener = (FragmentCallbackListener) activity;
	}

	public void setCardId(String idString) {
		mCardId = idString;
	}

	public void setConnectType(int type) {
		mConnectType = type;
	}

	public void setConnectStatus(int status) {
		mConnectStatus = status;
	}

	public void setBattery(int battery) {
		mBattery = battery;
	}

	public void setIcStatus(int status) {
		mIcStatus = status;
	}

	public void setHwStatus(int status) {
		mHwStatus = status;
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		System.out.println("onCreateView");
		View rootView = inflater.inflate(R.layout.fragment_status, container,
				false);
		about = (LinearLayout) rootView.findViewById(R.id.about_layout);
		about.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				mListener.updateSignal();
				// goto about activity
				Intent intent = new Intent(getActivity(), AboutActivity.class);
				startActivity(intent);
			}
		});

		cardNumberTextView = (TextView) rootView.findViewById(R.id.ic_number);
		cardNumberTextView.setText(mCardId);
		connectTypeTextView = (TextView) rootView
				.findViewById(R.id.connect_type);

		if (mConnectType == LoginActivity.CONNECT_TYPE_BLUETOOTH) {
			connectTypeTextView.setText("蓝牙");
		} else if (mConnectType == LoginActivity.CONNECT_TYPE_WIFI) {
			connectTypeTextView.setText("WIFI");
		} else if (mConnectType == LoginActivity.CONNECT_TYPE_NONE) {
			connectTypeTextView.setText("NONE");
		}

		connectStatusTextView = (TextView) rootView
				.findViewById(R.id.connect_status);
		connectStatusTextView.setText((mConnectStatus == 0) ? "未连接" : "已连接");
		batteryTextView = (TextView) rootView.findViewById(R.id.battery_status);
		batteryTextView.setText("" + mBattery + "%");
		icStatusTextView = (TextView) rootView.findViewById(R.id.ic_status);
		icStatusTextView.setText((mIcStatus == 0) ? "故障" : "正常");
		hwStatusTextView = (TextView) rootView
				.findViewById(R.id.hardware_status);
		hwStatusTextView.setText((mHwStatus == 0) ? "故障" : "正常");

		return rootView;
	}
}
